home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / solaris2 / jdk / src / java / awt / image / imagefil.jav < prev    next >
Encoding:
Text File  |  1995-10-30  |  4.5 KB  |  136 lines

  1. /*
  2.  * @(#)ImageFilter.java    1.10 95/09/08 Jim Graham
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.awt.image;
  21.  
  22. import java.util.Hashtable;
  23.  
  24. /**
  25.  * This class implements a filter for the set of interface methods that
  26.  * are used to deliver data from an ImageProducer to an ImageConsumer.
  27.  * It is meant to be used in conjunction with a FilteredImageSource
  28.  * object to produce filtered versions of existing images.  It is a
  29.  * base class that provides the calls needed to implement a "Null filter"
  30.  * which has no effect on the data being passed through.  Filters should
  31.  * subclass this class and override the methods which deal with the
  32.  * data that needs to be filtered and modify it as necessary.
  33.  *
  34.  * @see FilteredImageSource
  35.  * @see ImageConsumer
  36.  *
  37.  * @version    1.10 09/08/95
  38.  * @author     Jim Graham
  39.  */
  40. public class ImageFilter implements ImageConsumer {
  41.     /**
  42.      * The consumer of the particular image data stream that this
  43.      * instance of the ImageFilter is filtering data for.  It is not
  44.      * initialized during the constructor, but rather during the
  45.      * getFilterInstance() method call when the FilteredImageSource
  46.      * is creating a unique instance of this object for a particular
  47.      * image data stream.
  48.      * @see #getFilterInstance
  49.      * @see ImageConsumer
  50.      */
  51.     protected ImageConsumer consumer;
  52.  
  53.     /**
  54.      * Return a unique instance of an ImageFilter object which will
  55.      * actually perform the filtering for the specified ImageConsumer.
  56.      * The default implementation just clones this object.
  57.      */
  58.     public ImageFilter getFilterInstance(ImageConsumer ic) {
  59.     ImageFilter instance = (ImageFilter) clone();
  60.     instance.consumer = ic;
  61.     return instance;
  62.     }
  63.  
  64.     /**
  65.      * Filter the information provided in the setDimensions method
  66.      * of the ImageConsumer interface.
  67.      * @see ImageConsumer#setDimensions
  68.      */
  69.     public void setDimensions(int width, int height) {
  70.     consumer.setDimensions(width, height);
  71.     }
  72.  
  73.     /**
  74.      * Pass the properties from the source object along after adding a
  75.      * property indicating the stream of filters it has been run through.
  76.      */
  77.     public void setProperties(Hashtable props) {
  78.     Object o = props.get("filters");
  79.     if (o == null) {
  80.         props.put("filters", toString());
  81.     } else if (o instanceof String) {
  82.         props.put("filters", ((String) o)+toString());
  83.     }
  84.     consumer.setProperties(props);
  85.     }
  86.  
  87.     /**
  88.      * Filter the information provided in the setColorModel method
  89.      * of the ImageConsumer interface.
  90.      * @see ImageConsumer#setColorModel
  91.      */
  92.     public void setColorModel(ColorModel model) {
  93.     consumer.setColorModel(model);
  94.     }
  95.  
  96.     /**
  97.      * Filter the information provided in the setHints method
  98.      * of the ImageConsumer interface.
  99.      * @see ImageConsumer#setHints
  100.      */
  101.     public void setHints(int hints) {
  102.     consumer.setHints(hints);
  103.     }
  104.  
  105.     /**
  106.      * Filter the information provided in the setPixels method of the
  107.      * ImageConsumer interface which takes an array of bytes.
  108.      * @see ImageConsumer#setPixels
  109.      */
  110.     public void setPixels(int x, int y, int w, int h,
  111.               ColorModel model, byte pixels[], int off,
  112.               int scansize) {
  113.     consumer.setPixels(x, y, w, h, model, pixels, off, scansize);
  114.     }
  115.  
  116.     /**
  117.      * Filter the information provided in the setPixels method of the
  118.      * ImageConsumer interface which takes an array of integers.
  119.      * @see ImageConsumer#setPixels
  120.      */
  121.     public void setPixels(int x, int y, int w, int h,
  122.               ColorModel model, int pixels[], int off,
  123.               int scansize) {
  124.     consumer.setPixels(x, y, w, h, model, pixels, off, scansize);
  125.     }
  126.  
  127.     /**
  128.      * Filter the information provided in the imageComplete method of
  129.      * the ImageConsumer interface.
  130.      * @see ImageConsumer#imageComplete
  131.      */
  132.     public void imageComplete(int status) {
  133.     consumer.imageComplete(status);
  134.     }
  135. }
  136.